<?php

/**
 * 常用函数库
 */
namespace app\libs;

class Functions
{

    protected $_di;
    const Time_Out = 10;

    public function setDI(DiInterface $di)
    {
        $this->_di = $di;
    }

    public function getDI()
    {
        return $this->_di;
    }

    //获取后缀
    public function getExt($url)
    {
        $p = pathinfo($url);
        return $p['extension'];
    }


    //curl下载图片
    public function curlDownFile($url, $save_to)
    {
        //创建文件指针
        $handle = fopen($save_to, 'w');
        $ch = curl_init();
        if (stripos($url, "https://") !== FALSE) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_FILE, $handle);
        $sContent = curl_exec($ch);
        if ($error = curl_error($ch)) {
            die($error);
        }
        $aStatus = curl_getinfo($ch);
        curl_close($ch);
        if (intval($aStatus["http_code"]) == 200) {
            fwrite($handle, $sContent);
            fclose($handle);
        } else {
            return false;
        }
    }

    function getProvinceCity($ip)
    {
        $api = 'http://ip.ws.126.net/ipquery';
        $params = array('ip' => $ip);
        $content = self::curl_get($api, $params);
        $content = iconv("gbk", "utf8", $content);
        if ($content) {
            $pattern = '/city:"([\s\S]*)", province:"([\s\S]*)"/';
            preg_match($pattern, $content, $matches);
            $result['city'] = $matches[1];
            $result['province'] = $matches[2];
            return $result;
        }
        return $content;
    }

    //字符串加密
    public static function encrypt($data, $key)
    {
        $key = md5($key);
        $x = 0;
        $char = "";
        $str = "";
        $len = strlen($data);
        $l = strlen($key);
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) {
                $x = 0;
            }
            $char .= $key{$x};
            $x++;
        }
        for ($i = 0; $i < $len; $i++) {
            $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
        }
        return base64_encode($str);
    }

    //字符串解密
    public static function decrypt($data, $key)
    {
        $key = md5($key);
        $x = 0;
        $char = "";
        $str = "";
        $data = base64_decode($data);
        $len = strlen($data);
        $l = strlen($key);
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) {
                $x = 0;
            }
            $char .= substr($key, $x, 1);
            $x++;
        }
        for ($i = 0; $i < $len; $i++) {
            if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
                $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
            } else {
                $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
            }
        }
        return $str;
    }

    /**
     * 生成唯一字符串组合
     * @param int $num
     * @return string
     */
    public static function uniqueString($num = 18)
    {
        $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        $return_str = '';
        $i = 0;
        do {
            $i++;
            $return_str .= $string[mt_rand(0, 61)];
        } while ($i < $num);

        return $return_str;
    }

    /**
     * 生成数字号码(no-repeat)
     * @param int $num
     * return string
     */
    public static function numCodeNoRe($num = 4)
    {
        $string = "0123456789";
        $return_str = substr(str_shuffle($string), 0, $num);
        return $return_str;
    }

    /**
     * 生成数字号码(repeat)
     * @param type $num
     * @return string
     */
    function numCodeRe($num = 4)
    {
        $string = "0123456789";
        $return_str = '';
        $i = 0;
        do {
            $i++;
            $return_str .= $string[mt_rand(0, 9)];
        } while ($i < $num);

        return $return_str;
    }

    //替换键值
    function arrayKey($arr, $key)
    {
        $newArr = array();
        if ($arr) {
            foreach ($arr as $rs) {
                $newArr[$rs[$key]] = $rs;
            }
        }
        return $newArr;
    }

    /*
     * 计算时差
     * $param int $t1
     * $param int $t2
     * return string
     */
    function executeTime($t1, $t2)
    {
        return "耗时" . round($t2 - $t1, 3) . "秒";
    }

    /**
     * 创建文件夹
     * $param string $dir /apps/cache/logs
     * $param int $mode 0777
     * return boolean
     */
    function mkdirs($dir, $mode)
    {
        if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
        if (!self::mkdirs(dirname($dir), $mode)) return FALSE;
        return @mkdir($dir, $mode);
    }



    /**
     * 格式化视频上传日期
     * @param float $second 100.01
     * return string 12:32、65:23、1:34:23)
     */
    function formatPublished($published)
    {
        //差值
        $timeDiff = time() - (int)$published;
        if ($timeDiff <= 60) {
            return "1分钟前";
        } else if (60 < $timeDiff and $timeDiff <= 60 * 60) {
            return (int)($timeDiff / 60) . "分钟前";
        } else if (60 * 60 < $timeDiff and $timeDiff <= 60 * 60 * 24) {
            return (int)($timeDiff / (60 * 60)) . "小时前";
        } else if (60 * 60 * 24 < $timeDiff and $timeDiff <= 60 * 60 * 24 * 30) {
            return (int)($timeDiff / (60 * 60 * 24)) . "天前";
        } else if (60 * 60 * 24 * 30 < $timeDiff and $timeDiff <= 60 * 60 * 24 * 30 * 12) {
            return (int)($timeDiff / (60 * 60 * 24 * 30)) . "个月前";
        } else if (60 * 60 * 24 * 30 * 12 < $timeDiff) {
            return (int)($timeDiff / (60 * 60 * 24 * 30 * 12)) . "年前";
        }

    }

    /**
     * 格式化日期
     * @param float $second 100.01
     * return string 12:32、65:23、1:34:23)
     */
    function formatCreated($created)
    {
        $ymd = date('Y-m-d', $created);
        $ymdArr = explode('-', $ymd);
        $ymdNow = date('Y-m-d', time());
        $ymdNowArr = explode('-', $ymdNow);

        //今天
        if ($ymd == $ymdNow) {
            $timeDiff = time() - (int)$created;
            if ($timeDiff <= 60) {
                return "刚刚";
            } else if (60 < $timeDiff and $timeDiff <= 60 * 60) {
                return (int)($timeDiff / 60) . "分钟前";
            } else {
                return "今天 " . date('H:i', $created);
            }
            //今年
        } else if (date('Y', $created) == date('Y', time())) {
            return (int)$ymdArr[1] . "月" . (int)$ymdArr[2] . "日 " . date('H:i', $created);
        } else {
            return $ymdArr[0] . "-" . (int)$ymdArr[1] . "-" . (int)$ymdArr[2] . " " . date('H:i', $created);
        }


    }


    //获取密码强度0->低、1->较低、2->中、3->较高、4->高
    function passwordStrength($password)
    {
        $score = 0;
        if (preg_match("/[0-9]+/", $password)) {
            $score++;
        }
        if (preg_match("/[0-9]{3,}/", $password)) {
            $score++;
        }
        if (preg_match("/[a-z]+/", $password)) {
            $score++;
        }
        if (preg_match("/[a-z]{3,}/", $password)) {
            $score++;
        }
        if (preg_match("/[A-Z]+/", $password)) {
            $score++;
        }
        if (preg_match("/[A-Z]{3,}/", $password)) {
            $score++;
        }
        if (preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]+/", $password)) {
            $score += 2;
        }
        if (preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]{3,}/", $password)) {
            $score++;
        }
        if (strlen($password) >= 10) {
            $score++;
        }
        //返回0,1,2,3,4
        return ceil($score / 2);
    }


    //获取当前毫秒时间
    function msectime()
    {
        list($msec, $sec) = explode(' ', microtime());

        return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
    }


    //获取当前微秒数时间字符串
    function microtimeStr()
    {
        list ($usec, $sec) = explode(" ", microtime());
        return $sec . $usec * 1000000;
    }

    //阿里云oss部分
    //$time为过期时间戳
    function gmtIso8601($time)
    {
        $dtStr = date("c", $time);
        $mydatetime = new DateTime($dtStr);
        $expiration = $mydatetime->format(DateTime::ISO8601);
        $pos = strpos($expiration, '+');
        $expiration = substr($expiration, 0, $pos);
        return $expiration . "Z";
    }

    //获取签名后的url
    function getSignUrl($object, $query = '')
    {
        $config = $this->getDI()->get('config');
        $accessKeyId = $config['oss']['accessKeyId'];
        $accessKeySecret = $config['oss']['accessKeySecret'];
        $host = $config['oss']['host'];
        $bucket = $config['oss']['bucket'];
        if ($query) {
            $object = $object . '@' . $query;
        }
        $timeout = 3600;
        try {
            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $host, true);
            $signedUrl = $ossClient->signUrl($bucket, $object, $timeout);
            return $signedUrl;
        } catch (OssException $e) {
            $msg  = "File：" . $e->getFile() . "\n";
            $msg .= "Line：" . $e->getLine() . "\n";
            $msg .= "Message：" . $e->getMessage() . "\n";
            $this->getDI()->get('logger')->log($msg, "error",'db');

            print $e->getMessage();
        }
    }

    //浏览器文件下载（小文件直接下载）
    function downFile($path)
    {
        if (file_exists($path)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . basename($path));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($path));
            ob_clean();
            flush();
            readfile($path);
            exit;
        } else {
            echo "文件不存在";
        }
    }

    //inWhere条件拼接
    function inWhere($arr)
    {
        $str = '(';
        foreach ($arr as $value) {
            $str .= "'" . $value . "',";
        }
        if (strlen($str) > 1) {
            $str = substr($str, 0, -1) . ')';
        }
        return $str;
    }

    /**
     * combineURL
     * 拼接url
     * @param string $baseURL 基于的url
     * @param array $keysArr 参数列表数组
     * @return string           返回拼接的url
     */
    function combineURL($baseURL, $keysArr)
    {
        if (empty($keysArr) || !is_array($keysArr)) return $baseURL;

        $combined = $baseURL . "?";
        $valueArr = array();
        foreach ($keysArr as $key => $val) {
            $valueArr[] = "$key=" . urlencode($val);
        }
        $keyStr = implode("&", $valueArr);
        $combined .= ($keyStr);
        return $combined;
    }

    /**
     * 服务器通过get请求获得内容
     * @param  string $baseURL 基础URL
     * @param  array $keysArr 请求参数
     * @return string          [description]
     */


    function curlGet($baseURL, $keysArr = array(), $timeOut = 10)
    {
        $url = $this->combineURL($baseURL, $keysArr);
        $ch = curl_init();
        //    $headers[] = 'token: '.$keysArr['token'];
        $headers[] = '';

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        if (stripos($url, "https://") !== FALSE) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
        $sContent = curl_exec($ch);
        if ($error = curl_error($ch)) {
            return false;
        }
        $aStatus = curl_getinfo($ch);
        curl_close($ch);
        if (intval($aStatus["http_code"]) == 200) {
            return $sContent;
        } else {
            return false;
        }
    }

    function httpRequest($URL,$data=null,$type='GET',$headers=[]){
        $ch = curl_init();
        //判断ssl连接方式
        if(stripos($URL, 'https://') !== false) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSLVERSION, 1);
        }
        $connttime=300; //连接等待时间500毫秒
        $timeout = 15000;//超时时间15秒
        $querystring = "";
        if (is_array($data)) {
            // Change data in to postable data
            foreach ($data as $key => $val) {
                if (is_array($val)) {
                    foreach ($val as $val2) {
                        $querystring .= urlencode($key).'='.urlencode($val2).'&';
                    }
                } else {
                    $querystring .= urlencode($key).'='.urlencode($val).'&';
                }
            }
            $querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
        } else {
            $querystring = $data;
        }
        if($type == 'GET'){
            $URL  = $URL.'?'.$querystring;
        }
        //exit($URL);
        curl_setopt ($ch, CURLOPT_URL, $URL); //发贴地址
        //设置HEADER头部信息
//        var_dump($headers);
        if(!$headers){
            curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
        }else {
            curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type: text/json'));
        }
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);//反馈信息
        curl_setopt ($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); //http 1.1版本

        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT_MS, $connttime);//连接等待时间
        curl_setopt ($ch, CURLOPT_TIMEOUT_MS, $timeout);//超时时间

        switch ($type){
            case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true);break;
            case "POST": curl_setopt($ch, CURLOPT_POST,true);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$querystring);break;
            case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
                curl_setopt($ch, CURLOPT_POSTFIELDS,$querystring);break;
            case "DELETE":curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
                curl_setopt($ch, CURLOPT_POSTFIELDS,$querystring);break;
        }
        $file_contents = curl_exec($ch);//获得返回值
        $status = curl_getinfo($ch);
        curl_close($ch);
        return $file_contents;
    }


    /**
     * post方式请求资源
     * @param string $url 基于的baseUrl
     * @param array $keysArr 请求的参数列表
     * @return string           返回的资源内容
     */
    function curlPost($url, $keysArr = array(),$headers = [])
    {
        $ch = curl_init();
        if (stripos($url, "https://") !== false) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }

        $aPOST = array();
        foreach ($keysArr as $key => $val) {
            $aPOST[] = $key . "=" . urlencode($val);
        }
        $strPOST = implode("&", $aPOST);


        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $strPOST);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $sContent = curl_exec($ch);

        //    var_dump($sContent);

        $aStatus = curl_getinfo($ch);
        curl_close($ch);
        //    dd($aStatus);
        if (intval($aStatus["http_code"]) == 200) {
            return $sContent;
        } else {
            return false;
        }

    }


    function http_request($url,$type = "POST", $keysArr = array(), $headersArr = array(),$timeOut = 30){
        // var_dump($url);
        // var_dump($keysArr);
//        var_dump($headersArr);
//
//        var_dump(http_build_query($keysArr));
        //$headersArr['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36';
        if($type == "POST"){
            $ch = curl_init();
            if (stripos($url, "https://") !== false) {
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
            }

            $aPOST = array();
            foreach ($keysArr as $key => $val) {
                $aPOST[] = $key . "=" . urlencode($val);
            }
            $strPOST = implode("&", $aPOST);

            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, true);
            //带上headers
            if($headersArr){
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headersArr);
            }


            curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
            curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

            curl_setopt($ch, CURLOPT_POSTFIELDS, $strPOST);
            curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);

            $sContent = curl_exec($ch);
            $aStatus = curl_getinfo($ch);
//            var_dump($aStatus);exit;
            curl_close($ch);
            if (intval($aStatus["http_code"]) == 200) {
                if($sContent){
                    //echo 111;
                    return json_decode($sContent,true) ;
                }
//                echo 2222;
                return $sContent;
            }
        }else{
            $url = $this->combineURL($url, $keysArr);
            $ch = curl_init();
            if (stripos($url, "https://") !== FALSE) {
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
            }
            curl_setopt($ch, CURLOPT_URL, $url);
            if($headersArr){
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headersArr);
            }

            curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
            curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);


//            // 返回 response_header, 该选项非常重要,如果不为 true, 只会获得响应的正文
//            curl_setopt($ch, CURLOPT_HEADER, true);
//            // 是否不需要响应的正文,为了节省带宽及时间,在只需要响应头的情况下可以不要正文
//            curl_setopt($ch, CURLOPT_NOBODY, true);
//            //至关重要，CURLINFO_HEADER_OUT选项可以拿到请求头信息
//            curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
            $sContent = curl_exec($ch);

//            if ($error == curl_error($ch)) {
//                var_export($error);
//                return false;
//            }

            $aStatus = curl_getinfo($ch);

//            echo "<pre>";
//            var_export($sContent);
//            var_export($aStatus);
//            exit;

            curl_close($ch);
            if (intval($aStatus["http_code"]) == 200) {
                if($sContent){
                    return json_decode($sContent,true) ;
                }
                return $sContent;
            }
        }
    }



    function object_to_array($obj) {
        $obj = (array)$obj;
        foreach ($obj as $k => $v) {
            if (gettype($v) == 'resource') {
                return;
            }
            if (gettype($v) == 'object' || gettype($v) == 'array') {
                $obj[$k] = (array)object_to_array($v);
            }
        }

        return $obj;
    }

    function object2array($object) {
        if (is_object($object)) {
            foreach ($object as $key => $value) {
                $array[$key] = $value;
            }
        }
        else {
            $array = $object;
        }
        return $array;
    }

    //获取当前用户ip
    function getIp() {
        $unknown = 'unknown';
        if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)){
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        /**
         * 处理多层代理的情况
         * 或者使用正则方式：$ip = preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : $unknown;
         */
        if (false !== strpos($ip, ',')) $ip = reset(explode(',', $ip));
        $ipinf = $this->getIpInfo($ip);
//            if ($ipinf['city'] =='内网IP'){
//                $ipinf['city'] = '上海市';
//            }
        return $ipinf;
    }

    function getIpInfo($ip){
        $url='http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
//        $url='http://ip.taobao.com/service/getIpInfo.php?ip=169.235.24.133';
        $result = file_get_contents($url);
        $result = json_decode($result,true);
        if($result['code']!==0 || !is_array($result['data'])) return false;
        return $result['data'];
    }


    function uniqueNum($num = 18)
    {
        $firstString = "123456789";
        $string = "1234567890";
        $return_str = '';
        $i = 0;
        do {
            $i++;
            $return_str .= $string[mt_rand(0, 9)];
        } while ($i < $num - 1);
        $uniqueNum = $firstString[mt_rand(0, 8)].$return_str;
        return $uniqueNum;
    }

    function randNum($num = 9){
        $string = "0123456789";
        $return_str = '';
        $i = 0;
        do {
            $i++;
            $return_str .= $string[mt_rand(0, 9)];
        } while ($i < $num);

        return $return_str;
    }

    function createArticleNo(){
        if(function_exists('atom_next_id')){
            return atom_next_id();
        }
        return $this->uniqueNum(18);
    }

    //获取代理 IP
    function get_client_ip()
    {
        $unknown = 'unknown';
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        /**
         * 处理多层代理的情况
         * 或者使用正则方式：$ip = preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : $unknown;
         */
        if (false !== strpos($ip, ',')){
            $ipArr = explode(',', $ip);
            $ip = reset($ipArr);
            return $ip;
        }
        return $ip;
    }

    function createOrderNo()
    {
        if(function_exists('atom_next_id')){
            return atom_next_id();
        }
        return $this->uniqueNum(18);
    }
    function saveImage()
    {
        return date('YmdHis', time());
    }

//    function encryptPassword($password,$saltPassword)
//    {
//        return hash('sha256', $saltPassword . $password);
//    }
    public static  function encryptPassword($password = '', $saltPassword = '')
    {
        return hash('sha256', $saltPassword . $password);
    }
//	function encryptPassword($password = '', $saltPassword = '')
//	{
//		return hash('sha256', $saltPassword . $password);
//	}

    //判断小数位数
    public function getFloatLength($num) {
        $count = 0;

        $temp = explode ( '.', $num );

        if (sizeof ( $temp ) > 1) {
            $decimal = end ( $temp );
            $count = strlen ( $decimal );
        }

        return $count;
    }

    //获取浏览器默认语言
    public function getLanguage($accept_language = 'zh-CN,zh;q=0.9,en;q=0.8') {
        $lang = substr($accept_language,0,strpos($accept_language, ','));
        if($lang != 'zh-CN'){
            $lang = 'en-US';
        }
        return $lang;
    }


    //邮箱注册
    function emailRegisterBody($code)
    {
        $website = $this->getDI()->get('config')['website'];
        if ($website == 'http://127.0.0.1/') {
            $website = 'http://test.siwabuluo.com/';
        }
        $body = '<!DOCTYPE html>
            <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <title></title>
                    </head>
                <body>
                    <table border="0" cellpadding="0" cellspacing="0" width="700px"  style="border-collapse:collapse;margin: 0 auto;" class="ke-zeroborder">
                    <tbody>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="51" width="64">
                                <img src="' . $website . 'static/img/framework-top-left.png" style="display:block;" height="51" width="64">
                            </td>
                            <td background="' . $website . 'static/img/framework-top-middle.png" bgcolor="#f5f5f5" valign="bottom" height="51" width="100%">&nbsp;</td>
                            <td height="51" width="63">
                                <img src="' . $website . 'static/img/framework-top-right.png" style="display:block;" height="51" width="63">
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="" width="64" background="' . $website . 'static/img/framework-middle-2-left.png" valign="top">
                                <img src="' . $website . 'static/img/framework-middle-1-left.png" style="display:block;" height="400" width="64">
                            </td>
                            <td width="100%" bgcolor="#ffffff" valign="top" style="padding:15px 0 19px 0;">
                                <table style="border-collapse: collapse; border-spacing: 0; font-size: 16px; line-height: 1.5; margin: 0 auto; width: 400px">
                                    <tbody>
                                        <tr>
                                            <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                        <table width="100%" style="border-collapse: collapse; border-spacing: 0; margin-top: 30px">
                            <tbody>
                            <tr>
                                <td width="110"
                                    style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; vertical-align: bottom; word-break: break-word"
                                    valign="bottom">
                                    <a href="' . $website . '" target="_blank" style="color: #2ba6cb; text-decoration: none"><img
                                            src="' . $website . 'static/img/logo.png"
                                            style="-ms-interpolation-mode: bicubic; border: none; clear: both; display: block; float: left; height: auto; max-width: 100%; outline: none; text-decoration: none; width: 100px"
                                            align="left"></a>
                                </td>

                            </tr>
                            </tbody>
                        </table>

                        <hr style="background: #ddd; border: none; color: #ddd; height: 1px; margin: 20px 0 30px">

                        <table width="100%" style="border-collapse: collapse; border-spacing: 0">
                            <tbody>
                            <tr>
                                <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                                    <div>
                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            您好，shuffle团队提醒您</p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            感谢注册 SW部落，您的邮箱验证码为：
                                        </p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 24px 0; padding: 0">
                                            <a
                                               style="color: #2fb3ff; border-radius: 4px; font-size:24px;cursor:default;
                                               border-bottom:1px dashed #ccc; padding: 5px; text-decoration: none; word-break: break-all">
                                                ' . $code . '
                                            </a>
                                        </p>

                                        <p style="color: #999999; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 12px; margin: 0 0 10px; padding: 0">
                                            如果你没有注册过 SW部落，请忽略此邮件。</p>
                                    </div>

                                </td>
                            </tr>
                            </tbody>
                        </table>

                    </td>
                </tr>


                        </tbody>
                    </table>
                </td>
                <td height="" width="63" background="' . $website . 'static/img/framework-middle-2-right.png" valign="top">
                    <img src="' . $website . 'static/img/framework-middle-1-right.png" style="display:block;" height="400" width="63">
                </td>
                <td>&nbsp;</td>
            </tr>

        <tr>
            <td>&nbsp;</td>
            <td height="40" width="64">
                <img src="' . $website . 'static/img/framework-bottom-left.png" style="display:block;" height="40" width="64">
            </td>
            <td valign="top" height="" width="100%" background="' . $website . 'static/img/framework-bottom-middle.png">&nbsp;</td>
            <td height="40" width="63">
                <img src="' . $website . 'static/img/framework-bottom-right.png" style="display:block;" height="40" width="63">
            </td>
            <td>&nbsp;</td>
        </tr>
        </tbody>
    </table>
    </body>
    </html>';
        return $body;
    }

    //修改邮箱
    function emailChangeBody($code)
    {
        $website = $this->getDI()->get('config')['website'];
        $body = '<!DOCTYPE html>
            <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <title></title>
                    </head>
                <body>
                    <table border="0" cellpadding="0" cellspacing="0" width="700px"  style="border-collapse:collapse;margin: 0 auto;" class="ke-zeroborder">
                    <tbody>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="51" width="64">
                                <img src="' . $website . 'static/img/framework-top-left.png" style="display:block;" height="51" width="64">
                            </td>
                            <td background="' . $website . 'static/img/framework-top-middle.png" bgcolor="#f5f5f5" valign="bottom" height="51" width="100%">&nbsp;</td>
                            <td height="51" width="63">
                                <img src="' . $website . 'static/img/framework-top-right.png" style="display:block;" height="51" width="63">
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="" width="64" background="' . $website . 'static/img/framework-middle-2-left.png" valign="top">
                                <img src="' . $website . 'static/img/framework-middle-1-left.png" style="display:block;" height="400" width="64">
                            </td>
                            <td width="100%" bgcolor="#ffffff" valign="top" style="padding:15px 0 19px 0;">
                                <table style="border-collapse: collapse; border-spacing: 0; font-size: 16px; line-height: 1.5; margin: 0 auto; width: 400px">
                                    <tbody>
                                        <tr>
                                            <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                        <table width="100%" style="border-collapse: collapse; border-spacing: 0; margin-top: 30px">
                            <tbody>
                            <tr>
                                <td width="110"
                                    style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; vertical-align: bottom; word-break: break-word"
                                    valign="bottom">
                                    <a href="' . $website . '" target="_blank" style="color: #2ba6cb; text-decoration: none"><img
                                            src="' . $website . 'static/img/logo.png"
                                            style="-ms-interpolation-mode: bicubic; border: none; clear: both; display: block; float: left; height: auto; max-width: 100%; outline: none; text-decoration: none; width: 100px"
                                            align="left"></a>
                                </td>

                            </tr>
                            </tbody>
                        </table>

                        <hr style="background: #ddd; border: none; color: #ddd; height: 1px; margin: 20px 0 30px">

                        <table width="100%" style="border-collapse: collapse; border-spacing: 0">
                            <tbody>
                            <tr>
                                <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                                    <div>
                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            您好，shuffle团队提醒您！</p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            您正在修改绑定邮箱，验证码为：
                                        </p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 24px 0; padding: 0">
                                            <a
                                               style="color: #2fb3ff; border-radius: 4px; font-size:24px;cursor:default;
                                               border-bottom:1px dashed #ccc; padding: 5px; text-decoration: none; word-break: break-all">
                                                ' . $code . '
                                            </a>
                                        </p>

                                        <p style="color: #999999; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 12px; margin: 0 0 10px; padding: 0">
                                            如果你没有注册过 shuffle，请忽略此邮件。</p>
                                    </div>

                                </td>
                            </tr>
                            </tbody>
                        </table>

                    </td>
                </tr>


                        </tbody>
                    </table>
                </td>
                <td height="" width="63" background="' . $website . 'static/img/framework-middle-2-right.png" valign="top">
                    <img src="' . $website . 'static/img/framework-middle-1-right.png" style="display:block;" height="400" width="63">
                </td>
                <td>&nbsp;</td>
            </tr>

        <tr>
            <td>&nbsp;</td>
            <td height="40" width="64">
                <img src="' . $website . 'static/img/framework-bottom-left.png" style="display:block;" height="40" width="64">
            </td>
            <td valign="top" height="" width="100%" background="' . $website . 'static/img/framework-bottom-middle.png">&nbsp;</td>
            <td height="40" width="63">
                <img src="' . $website . 'static/img/framework-bottom-right.png" style="display:block;" height="40" width="63">
            </td>
            <td>&nbsp;</td>
        </tr>
        </tbody>
    </table>
    </body>
    </html>';
        return $body;
    }

    //重置密码
    function emailResetPasswordBody($code)
    {
        $website = $this->getDI()->get('config')['website'];
        $body = '<!DOCTYPE html>
            <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <title></title>
                    </head>
                <body>
                    <table border="0" cellpadding="0" cellspacing="0" width="700px"  style="border-collapse:collapse;margin: 0 auto;" class="ke-zeroborder">
                    <tbody>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="51" width="64">
                                <img src="' . $website . 'static/img/framework-top-left.png" style="display:block;" height="51" width="64">
                            </td>
                            <td background="' . $website . 'static/img/framework-top-middle.png" bgcolor="#f5f5f5" valign="bottom" height="51" width="100%">&nbsp;</td>
                            <td height="51" width="63">
                                <img src="' . $website . 'static/img/framework-top-right.png" style="display:block;" height="51" width="63">
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="" width="64" background="' . $website . 'static/img/framework-middle-2-left.png" valign="top">
                                <img src="' . $website . 'static/img/framework-middle-1-left.png" style="display:block;" height="400" width="64">
                            </td>
                            <td width="100%" bgcolor="#ffffff" valign="top" style="padding:15px 0 19px 0;">
                                <table style="border-collapse: collapse; border-spacing: 0; font-size: 16px; line-height: 1.5; margin: 0 auto; width: 400px">
                                    <tbody>
                                        <tr>
                                            <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                        <table width="100%" style="border-collapse: collapse; border-spacing: 0; margin-top: 30px">
                            <tbody>
                            <tr>
                                <td width="110"
                                    style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; vertical-align: bottom; word-break: break-word"
                                    valign="bottom">
                                    <a href="' . $website . '" target="_blank" style="color: #2ba6cb; text-decoration: none"><img
                                            src="' . $website . 'static/img/logo.png"
                                            style="-ms-interpolation-mode: bicubic; border: none; clear: both; display: block; float: left; height: auto; max-width: 100%; outline: none; text-decoration: none; width: 100px"
                                            align="left"></a>
                                </td>

                            </tr>
                            </tbody>
                        </table>

                        <hr style="background: #ddd; border: none; color: #ddd; height: 1px; margin: 20px 0 30px">

                        <table width="100%" style="border-collapse: collapse; border-spacing: 0">
                            <tbody>
                            <tr>
                                <td style="-moz-hyphens: auto; -webkit-hyphens: auto; border-collapse: collapse !important; color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; hyphens: auto; margin: 0; padding: 0; word-break: break-word">
                                    <div>
                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            您好，shuffle团队提醒您！</p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 0 0 10px; padding: 0">
                                            您正在重置密码，验证码为：
                                        </p>

                                        <p style="color: #222; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 16px; margin: 24px 0; padding: 0">
                                            <a
                                               style="color: #2fb3ff; border-radius: 4px; font-size:24px;cursor:default;
                                               border-bottom:1px dashed #ccc; padding: 5px; text-decoration: none; word-break: break-all">
                                                ' . $code . '
                                            </a>
                                        </p>

                                        <p style="color: #999999; font-family: \'Helvetica\', \'Arial\', sans-serif; font-size: 12px; margin: 0 0 10px; padding: 0">
                                            如果你没有注册过 shuffle，请忽略此邮件。</p>
                                    </div>

                                </td>
                            </tr>
                            </tbody>
                        </table>

                    </td>
                </tr>


                        </tbody>
                    </table>
                </td>
                <td height="" width="63" background="' . $website . 'static/img/framework-middle-2-right.png" valign="top">
                    <img src="' . $website . 'static/img/framework-middle-1-right.png" style="display:block;" height="400" width="63">
                </td>
                <td>&nbsp;</td>
            </tr>

        <tr>
            <td>&nbsp;</td>
            <td height="40" width="64">
                <img src="' . $website . 'static/img/framework-bottom-left.png" style="display:block;" height="40" width="64">
            </td>
            <td valign="top" height="" width="100%" background="' . $website . 'static/img/framework-bottom-middle.png">&nbsp;</td>
            <td height="40" width="63">
                <img src="' . $website . 'static/img/framework-bottom-right.png" style="display:block;" height="40" width="63">
            </td>
            <td>&nbsp;</td>
        </tr>
        </tbody>
    </table>
    </body>
    </html>';
        return $body;
    }

    public function genUuid(): string
    {
        if (function_exists('atom_next_id')) {
            return atom_next_id();
        }
        return false;
    }

    public function parseUid($uid): array
    {
        if (function_exists('atom_explain')) {
            return atom_explain($uid);
        }
        return false;
    }

    function genTokenWithUserAgentAndIp()
    {
        $ip = $this->getDI()->get('request')->getClientAddress();
        $agent = $this->getDI()->get('request')->getUserAgent();
        $uniString = $this->uniqueString(32);
        return md5($ip . $agent . $uniString);
    }

    function numberFormat($num,$decimail='8'){
        return number_format($num,$decimail,'.','');
    }

    //舍去小数
    function numFoor($num,$decimal='2'){
        $nummid = '1';
        for($i = 0; $i < $decimal; $i++){
            $nummid .= '0';
        }

        $num1 = $num * $nummid;
        $num2 = floor($num1);
        $result = $num2 / $nummid;
        return $result;
    }

    //替换键值
    function replaceKey($arr,$val){

        $newarr=array();

        if($arr){

            foreach($arr as $rs){

                $newarr[$rs[$val]]=$rs;

            }

        }

        return $newarr;

    }

    //重写bc函数
    function bcAdd($num1,$num2,$decimal = 8){
        $num1 = number_format($num1,'8','.','');
        $num2 = number_format($num2,'8','.','');
        return bcadd($num1,$num2,$decimal);
    }

    function bcSub($num1,$num2,$decimal = 8){
        $num1 = number_format($num1,'8','.','');
        $num2 = number_format($num2,'8','.','');
        return bcsub($num1,$num2,$decimal);
    }

    function bcMul($num1,$num2,$decimal = 8){
        $num1 = number_format($num1,'8','.','');
        $num2 = number_format($num2,'8','.','');
        return bcmul($num1,$num2,$decimal);
    }

    function bcComp($num1,$num2,$decimal = 8)
    {
        $num1 = number_format($num1, '8', '.', '');
        $num2 = number_format($num2, '8', '.', '');
        return bccomp($num1, $num2, $decimal);
    }

    function bcDiv($num1,$num2,$decimal = 8){
        $num1 = number_format($num1,'8','.','');
        $num2 = number_format($num2,'8','.','');
        return bcdiv($num1,$num2,$decimal);
    }

    public static function rand_cn_name(){
        $nicheng_tou=array('快乐的','冷静的','醉熏的','潇洒的','糊涂的','积极的','冷酷的','深情的','粗暴的','温柔的','可爱的','愉快的','义气的','认真的','威武的','帅气的','传统的','潇洒的','漂亮的','自然的','专一的','听话的','昏睡的','狂野的','等待的','搞怪的','幽默的','魁梧的','活泼的','开心的','高兴的','超帅的','留胡子的','坦率的','直率的','轻松的','痴情的','完美的','精明的','无聊的','有魅力的','丰富的','繁荣的','饱满的','炙热的','暴躁的','碧蓝的','俊逸的','英勇的','健忘的','故意的','无心的','土豪的','朴实的','兴奋的','幸福的','淡定的','不安的','阔达的','孤独的','独特的','疯狂的','时尚的','落后的','风趣的','忧伤的','大胆的','爱笑的','矮小的','健康的','合适的','玩命的','沉默的','斯文的','香蕉','苹果','鲤鱼','鳗鱼','任性的','细心的','粗心的','大意的','甜甜的','酷酷的','健壮的','英俊的','霸气的','阳光的','默默的','大力的','孝顺的','忧虑的','着急的','紧张的','善良的','凶狠的','害怕的','重要的','危机的','欢喜的','欣慰的','满意的','跳跃的','诚心的','称心的','如意的','怡然的','娇气的','无奈的','无语的','激动的','愤怒的','美好的','感动的','激情的','激昂的','震动的','虚拟的','超级的','寒冷的','精明的','明理的','犹豫的','忧郁的','寂寞的','奋斗的','勤奋的','现代的','过时的','稳重的','热情的','含蓄的','开放的','无辜的','多情的','纯真的','拉长的','热心的','从容的','体贴的','风中的','曾经的','追寻的','儒雅的','优雅的','开朗的','外向的','内向的','清爽的','文艺的','长情的','平常的','单身的','伶俐的','高大的','懦弱的','柔弱的','爱笑的','乐观的','耍酷的','酷炫的','神勇的','年轻的','唠叨的','瘦瘦的','无情的','包容的','顺心的','畅快的','舒适的','靓丽的','负责的','背后的','简单的','谦让的','彩色的','缥缈的','欢呼的','生动的','复杂的','慈祥的','仁爱的','魔幻的','虚幻的','淡然的','受伤的','雪白的','高高的','糟糕的','顺利的','闪闪的','羞涩的','缓慢的','迅速的','优秀的','聪明的','含糊的','俏皮的','淡淡的','坚强的','平淡的','欣喜的','能干的','灵巧的','友好的','机智的','机灵的','正直的','谨慎的','俭朴的','殷勤的','虚心的','辛勤的','自觉的','无私的','无限的','踏实的','老实的','现实的','可靠的','务实的','拼搏的','个性的','粗犷的','活力的','成就的','勤劳的','单纯的','落寞的','朴素的','悲凉的','忧心的','洁净的','清秀的','自由的','小巧的','单薄的','贪玩的','刻苦的','干净的','壮观的','和谐的','文静的','调皮的','害羞的','安详的','自信的','端庄的','坚定的','美满的','舒心的','温暖的','专注的','勤恳的','美丽的','腼腆的','优美的','甜美的','甜蜜的','整齐的','动人的','典雅的','尊敬的','舒服的','妩媚的','秀丽的','喜悦的','甜美的','彪壮的','强健的','大方的','俊秀的','聪慧的','迷人的','陶醉的','悦耳的','动听的','明亮的','结实的','魁梧的','标致的','清脆的','敏感的','光亮的','大气的','老迟到的','知性的','冷傲的','呆萌的','野性的','隐形的','笑点低的','微笑的','笨笨的','难过的','沉静的','火星上的','失眠的','安静的','纯情的','要减肥的','迷路的','烂漫的','哭泣的','贤惠的','苗条的','温婉的','发嗲的','会撒娇的','贪玩的','执着的','眯眯眼的','花痴的','想人陪的','眼睛大的','高贵的','傲娇的','心灵美的','爱撒娇的','细腻的','天真的','怕黑的','感性的','飘逸的','怕孤独的','忐忑的','高挑的','傻傻的','冷艳的','爱听歌的','还单身的','怕孤单的','懵懂的');
        $nicheng_wei=array('嚓茶','凉面','便当','毛豆','花生','可乐','灯泡','哈密瓜','野狼','背包','眼神','缘分','雪碧','人生','牛排','蚂蚁','飞鸟','灰狼','斑马','汉堡','悟空','巨人','绿茶','自行车','保温杯','大碗','墨镜','魔镜','煎饼','月饼','月亮','星星','芝麻','啤酒','玫瑰','大叔','小伙','哈密瓜，数据线','太阳','树叶','芹菜','黄蜂','蜜粉','蜜蜂','信封','西装','外套','裙子','大象','猫咪','母鸡','路灯','蓝天','白云','星月','彩虹','微笑','摩托','板栗','高山','大地','大树','电灯胆','砖头','楼房','水池','鸡翅','蜻蜓','红牛','咖啡','机器猫','枕头','大船','诺言','钢笔','刺猬','天空','飞机','大炮','冬天','洋葱','春天','夏天','秋天','冬日','航空','毛衣','豌豆','黑米','玉米','眼睛','老鼠','白羊','帅哥','美女','季节','鲜花','服饰','裙子','白开水','秀发','大山','火车','汽车','歌曲','舞蹈','老师','导师','方盒','大米','麦片','水杯','水壶','手套','鞋子','自行车','鼠标','手机','电脑','书本','奇迹','身影','香烟','夕阳','台灯','宝贝','未来','皮带','钥匙','心锁','故事','花瓣','滑板','画笔','画板','学姐','店员','电源','饼干','宝马','过客','大白','时光','石头','钻石','河马','犀牛','西牛','绿草','抽屉','柜子','往事','寒风','路人','橘子','耳机','鸵鸟','朋友','苗条','铅笔','钢笔','硬币','热狗','大侠','御姐','萝莉','毛巾','期待','盼望','白昼','黑夜','大门','黑裤','钢铁侠','哑铃','板凳','枫叶','荷花','乌龟','仙人掌','衬衫','大神','草丛','早晨','心情','茉莉','流沙','蜗牛','战斗机','冥王星','猎豹','棒球','篮球','乐曲','电话','网络','世界','中心','鱼','鸡','狗','老虎','鸭子','雨','羽毛','翅膀','外套','火','丝袜','书包','钢笔','冷风','八宝粥','烤鸡','大雁','音响','招牌','胡萝卜','冰棍','帽子','菠萝','蛋挞','香水','泥猴桃','吐司','溪流','黄豆','樱桃','小鸽子','小蝴蝶','爆米花','花卷','小鸭子','小海豚','日记本','小熊猫','小懒猪','小懒虫','荔枝','镜子','曲奇','金针菇','小松鼠','小虾米','酒窝','紫菜','金鱼','柚子','果汁','百褶裙','项链','帆布鞋','火龙果','奇异果','煎蛋','唇彩','小土豆','高跟鞋','戒指','雪糕','睫毛','铃铛','手链','香氛','红酒','月光','酸奶','银耳汤','咖啡豆','小蜜蜂','小蚂蚁','蜡烛','棉花糖','向日葵','水蜜桃','小蝴蝶','小刺猬','小丸子','指甲油','康乃馨','糖豆','薯片','口红','超短裙','乌冬面','冰淇淋','棒棒糖','长颈鹿','豆芽','发箍','发卡','发夹','发带','铃铛','小馒头','小笼包','小甜瓜','冬瓜','香菇','小兔子','含羞草','短靴','睫毛膏','小蘑菇','跳跳糖','小白菜','草莓','柠檬','月饼','百合','纸鹤','小天鹅','云朵','芒果','面包','海燕','小猫咪','龙猫','唇膏','鞋垫','羊','黑猫','白猫','万宝路','金毛','山水','音响');
        $tou_num=rand(0,331);$wei_num=rand(0,325);
        $nicheng=$nicheng_tou[$tou_num].$nicheng_wei[$wei_num];
        return $nicheng; //输出生成的昵称
    }
}
